<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    function shu(min,max){
        return Math.floor(Math.random()*(max-min+1))+min;
    }
    function u(arr,n){
         var newarr = [];
    for(var i = 1; i<=n;i++){
        var a = shu(0,arr.length-1);
        //如果新数组里面没有a
        if(newarr.indexOf(arr[a])==-1){
            //那么你就push进去
            newarr.push(arr[a])
        }else{
            //如果新数组里面已经有过a这个数字，那么就让i-1，再重新循环一次
            i--;
        }
    }
    return newarr;
}
   console.log(u(['小明','小红','小黄','小黑','小白','小紫','小小'],3));
</script>